package main.niit.dao;

import main.niit.pojo.*;
import main.niit.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Get2 {
    public List<Top10Category> getall() throws Exception {
        Connection connection=JDBCUtils.getConnection();

        List<Top10Category> list2= new ArrayList<>();


        PreparedStatement ps2=null;

        ResultSet resultSet2=null;

        try {
            String sql2 = "SELECT taskid, `clickcount` FROM top10_category;";
            ps2 = connection.prepareStatement(sql2);
            resultSet2 = ps2.executeQuery();
            while (resultSet2.next()) {
                Top10Category top10Category= new Top10Category();
                top10Category.setTaskId(resultSet2.getString("taskid"));
                top10Category.setClickCount(resultSet2.getLong("clickcount"));
                list2.add(top10Category);
            }
        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            JDBCUtils.close(ps2,connection);
        }

        return list2;

    }
}
